package com.dartfar.dictionary.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.dartfar.base.dao.DaoUtil;
import com.dartfar.base.model.Person;
import com.dartfar.base.service.BaseServiceImpl;
import com.dartfar.dictionary.model.Dictionary;
import com.dartfar.organize.model.Department;

@Component("dictionaryService")
public class DictionaryServiceImpl extends BaseServiceImpl<Dictionary> implements DictionaryService {

	@Resource
	private DaoUtil<Dictionary> dictionaryDaoUtil;

	//获取全部列表
	@Override
	public List<Dictionary> getList() {
		return dictionaryDaoUtil.getList("from Dictionary");
	}
	
	//根据字典目录获取字典列表
	@Override
	public List<Dictionary> getListByDictCatalog(int dclId){
		String hql = "from Dictionary d where d.dictCatalog.id = " + dclId;
		return dictionaryDaoUtil.getList(hql);
	}
	
	//获取目录列表
	@Override
	public List<Dictionary> getDictCatalogList(int pageNo, int pageSize) {
		return dictionaryDaoUtil.getListForPage("from Dictionary d where d.parentDict is null", (pageNo-1)*pageSize, pageSize);
	}

	//获取字典目录记录总数
	public Long getDictCatalogCount(){
		return dictionaryDaoUtil.getCount("from Dictionary d where d.parentDict is null");
	}
	
	//根据权限获取分页列表
	@Override
	public List<Dictionary> getListByAut(String code, Person person, Department depart, int pageNo, int pageSize) {
		String hql = "from Dictionary";
		return dictionaryDaoUtil.getListForPageByAut(hql, code, person, depart, pageNo, pageSize);
	}

	//根据权限获取列表记录
	@Override
	public Long getCountByAut(String code, Person person, Department depart){
		String hql = "from Dictionary";
		return dictionaryDaoUtil.getCountByAut(hql, code, person, depart);
	}
	

}
